package com.yuanzheng.test.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

/**
 * @author Administrator
 */
@Component
public class JedisUtil {

    @Autowired
    private JedisConfig jedisConfig;

    private Jedis jedis;

    public synchronized String setCache(String key, String value) {
        if (jedis == null) {
            String host = jedisConfig.getHost();
            int port = jedisConfig.getPort();
            int database = jedisConfig.getDatabase();
            jedis = new Jedis(host, port);
            jedis.select(database);
        }
        return jedis.set(key, value);
    }

}
